package com.etc.dao.impl;

import java.util.List;

import com.etc.dao.AnsAnswerDao;
import com.etc.dao.BaseDao;
import com.etc.entity.AnsAnswer;

public class AnsAnswerDaoImpl extends BaseDao implements AnsAnswerDao {

	@Override
	public int answerAnsMessage(AnsAnswer a) {
		String	sql="insert into ansanswers_info(id,username,title,type,content,date,status,ansid) values(?,?,?,?,?,CURRENT_TIMESTAMP(),'正常',?)";
		Object[] args= {a.getId(),a.getUsername(),a.getTitle(),a.getType(),a.getContent(),a.getAnsid()};
		return this.myExecuteUpdate(sql, args);
	}

	@Override
	public List<AnsAnswer> findAnswerAnsMessage(int id) {
		// TODO Auto-generated method stub
		String sql="select * from ansanswers_info where ansid=? ORDER BY date desc";
		Object[] args= {id};
		return this.listResult(AnsAnswer.class, sql, args);
	}

	@Override
	public int deleteAnsAnswer(int id) {
		// TODO Auto-generated method stub
		String sql="delete from ansanswers_info where id=?";
		Object[] args= {id};
		return this.myExecuteUpdate(sql, args);
	}

	@Override
	public int closeAnsAnswer(int id) {
		// TODO Auto-generated method stub
		String sql="update ansanswers_info set status=? where id=?";
		Object[] args= {"封禁",id};
		return this.myExecuteUpdate(sql, args);
	}

	@Override
	public int openAnsAnswer(int id) {
		// TODO Auto-generated method stub
		String sql="update ansanswers_info set status=? where id=?";
		Object[] args= {"正常",id};
		return this.myExecuteUpdate(sql, args);
	}

	@Override
	public List<AnsAnswer> findUserAnsAnswer(String username) {
		// TODO Auto-generated method stub
		String sql="select * from ansanswers_info where username=? ORDER BY date desc";
		Object[] args = {username};
		return this.listResult(AnsAnswer.class, sql, args);
	}

	@Override
	public List<AnsAnswer> searchAllAnsAnswer() {
		// TODO Auto-generated method stub
		String sql="select * from ansanswers_info ORDER BY date desc";
		return this.listResult(AnsAnswer.class, sql, null);
	}

	@Override
	public int findUpid(int ansid) {
		// TODO Auto-generated method stub
		String	sql="select ansid from ansmessages_info where id=?";
		Object[] args= {ansid};
		return this.myExecuteUpdate(sql, args);
	}

}
